package week1;
import java.util.*;
import java.io.*;
public class _503_借教室_暴力 {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		int r[] = new int[n+1];// 当天可用于租借教室的数量
		int d,s,t; // 租借数量，开始时间，结束时间
		
		st = new StringTokenizer(br.readLine());
		for(int i = 1; i <= n; i++) {
			r[i] = Integer.parseInt(st.nextToken());
		}
		
		int order = 0;
		boolean flag = false;
		while(++order <= m) {
			st = new StringTokenizer(br.readLine());
			d = Integer.parseInt(st.nextToken());
			s = Integer.parseInt(st.nextToken());
			t = Integer.parseInt(st.nextToken());
			
			for(int i = s; i <= t; i++) {
				r[i] -= d;
				if(r[i] < 0) {
					bw.write(-1 + "\n");
					bw.write(order + "\n");
					flag = true;
					break;
				}
			}
			
			if(flag) {
				break;
			}

		}
		
		if(!flag) {
			bw.write(0);
		}
		
		
		bw.flush();
		
	}
}
